// components/floatingFrame/index.js
var app = getApp();
var rootDocment = app.globalData.postUrl;
Component({

  /**
   * 页面的初始数据
   */
  properties: {
    is_write_style: {
      type: Boolean,
      value: true,

    },
    is_share: {
      type: Boolean,
      value: false
    },
    is_home: {
      type: Boolean,
      value: false
    }
  },

  data: {
    isShow: false, //是否已经弹出
    animMain: {}, //旋转动画
    animAdd: {}, //item位移,透明度
    animDelLots: {}, //item位移,透明度
    animEnd: {}, //item位移,透明度,
    isLogin: false,
    icon_img: '../../images/noExpanded.png',
    isBaBtn: true,
    animleft: {},
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    console.log('{{{{{{{{}}}}}}})_+_)_()**&&^%%%$');
  },
  created() {

  },
  /**
   * 组件的方法列表
   */
  methods: {
    //点击弹出或者收起
    showOrHide: function () {
      if (this.data.isShow) {
        //缩回动画
        this.takeback();
        this.setData({
          isShow: false
        })
      } else {
        //弹出动画
        this.popp();
        this.setData({
          isShow: true
        })
      }
    },

    //弹出动画
    popp: function () {
      //main按钮顺时针旋转
      console.log(1);
      var animationMain = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      var animationDelLots = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      var animationAdd = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      var animationEnd = wx.createAnimation({
        duration: 500,
        timingFunction: 'linear'
      })
      this.setData({
        icon_img: '../../images/expanded.png',
        isBaBtn: false
      })
      animationMain.rotateZ(90).step();
      animationDelLots.translate(0, -240 / 750 * 20).opacity(1).step();
      animationAdd.translate(0, -360 / 750 * 20).opacity(1).step();
      animationEnd.translate(-230, -170).opacity(1).step();
      this.setData({
        animMain: animationMain.export(),
        animDelLots: animationDelLots.export(),
        animAdd: animationAdd.export(),
        animEnd: animationEnd.export(),
      })
      let that = this
      let id = wx.getStorageSync('user_id3')
      if (id) {
        wx.request({
          url: rootDocment + '/api_cart',
          data: {
            user_id: id
          },
          method: 'GET',
          header: {},
          success: function (res) {
            if (res.statusCode == 200) {
              let is = res.data.length
              that.setData({
                is: res.data.length
              })
            }
          }
        })
      }
    },

    //收回动画
    takeback: function () {
      console.log(1);

      //main按钮逆时针旋转
      var animationMain = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      var animationDelLots = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      var animationAdd = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      var animationEnd = wx.createAnimation({
        duration: 500,
        timingFunction: 'ease-out'
      })
      this.setData({
        icon_img: '../../images/noExpanded.png',
        isBaBtn: true
      })
      animationMain.rotateZ(0).step();
      animationDelLots.translate(0, 0).rotateZ(0).opacity(0).step();
      animationAdd.translate(0, 0).rotateZ(0).opacity(0).step();
      animationEnd.translate(0, 0).rotateZ(0).opacity(0).step();
      this.setData({
        animMain: animationMain.export(),
        animDelLots: animationDelLots.export(),
        animAdd: animationAdd.export(),
        animEnd: animationEnd.export(),
      })
      setTimeout(() => {

      }, 500)
    },
    // 点击按钮
    isHide() {

      if (this.data.isShow) {
        this.takeback();
        this.setData({
          isShow: false
        })
      }

    },
    btn_type(e) {
      console.log(e.currentTarget.dataset.type);
      let type = e.currentTarget.dataset.type
      if (type == 1) {
        wx.switchTab({
          url: '/pages/index/index',
        })
      } else if (type == 2) {
        wx.navigateTo({
          url: '/pages/cart/index',
        })
        // wx.switchTab({
        //   url: '/pages/cart/index',
        // })
      } else {
        wx.pageScrollTo({
          scrollTop: 0
        })
      }
    },

  },
  observers: {
    is_write_style: function (newArr) {


      if (newArr) {
        let animationleft = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease-out'
        })
        animationleft.translate(0, 0).opacity(1).step();
        this.setData({
          animleft: animationleft.export(),
          // isShow: newArr
        })
      } else {
        let animationleft = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease-out'
        })
        animationleft.translate(80, 0).opacity(1).step();
        this.setData({
          animleft: animationleft.export(),
          // isShow: newArr
        })
      }
    },
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log(333);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})